home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch10 / Julia.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-06-09  |  19.3 KB  |  619 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form frmJulia 
  4.    Caption         =   "Julia"
  5.    ClientHeight    =   3810
  6.    ClientLeft      =   2370
  7.    ClientTop       =   1320
  8.    ClientWidth     =   3810
  9.    LinkTopic       =   "Form1"
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   254
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   254
  14.    Begin MSComDlg.CommonDialog dlgFile 
  15.       Left            =   120
  16.       Top             =   120
  17.       _ExtentX        =   847
  18.       _ExtentY        =   847
  19.       _Version        =   393216
  20.    End
  21.    Begin VB.PictureBox picCanvas 
  22.       AutoRedraw      =   -1  'True
  23.       BackColor       =   &H00000000&
  24.       Height          =   3810
  25.       Left            =   0
  26.       MousePointer    =   2  'Cross
  27.       ScaleHeight     =   250
  28.       ScaleMode       =   3  'Pixel
  29.       ScaleWidth      =   250
  30.       TabIndex        =   0
  31.       Top             =   0
  32.       Width           =   3810
  33.    End
  34.    Begin VB.Menu mnuFile 
  35.       Caption         =   "&File"
  36.       Begin VB.Menu mnuFileSaveAs 
  37.          Caption         =   "&Save As..."
  38.          Shortcut        =   ^A
  39.       End
  40.    End
  41.    Begin VB.Menu mnuScaleMnu 
  42.       Caption         =   "&Scale"
  43.       Begin VB.Menu mnuScale 
  44.          Caption         =   "x&2"
  45.          Index           =   2
  46.       End
  47.       Begin VB.Menu mnuScale 
  48.          Caption         =   "x&4"
  49.          Index           =   4
  50.       End
  51.       Begin VB.Menu mnuScale 
  52.          Caption         =   "x&8"
  53.          Index           =   8
  54.       End
  55.       Begin VB.Menu mnuScaleFull 
  56.          Caption         =   "&Full Scale"
  57.       End
  58.    End
  59.    Begin VB.Menu mnuOpt 
  60.       Caption         =   "&Options"
  61.       Begin VB.Menu mnuOptOptions 
  62.          Caption         =   "&Set Options"
  63.       End
  64.       Begin VB.Menu mnuOptSep 
  65.          Caption         =   "-"
  66.       End
  67.       Begin VB.Menu mnuOptMandelbrotSet 
  68.          Caption         =   "&Mandelbrot Set"
  69.          Checked         =   -1  'True
  70.          Shortcut        =   ^M
  71.       End
  72.       Begin VB.Menu mnuOptJuliaSet 
  73.          Caption         =   "&Julia Set"
  74.          Shortcut        =   ^J
  75.       End
  76.    End
  77.    Begin VB.Menu mnuMovie 
  78.       Caption         =   "&Movie"
  79.       Begin VB.Menu mnuMovieCreate 
  80.          Caption         =   "&Create Movie..."
  81.       End
  82.    End
  83. Attribute VB_Name = "frmJulia"
  84. Attribute VB_GlobalNameSpace = False
  85. Attribute VB_Creatable = False
  86. Attribute VB_PredeclaredId = True
  87. Attribute VB_Exposed = False
  88. Option Explicit
  89. Private m_DrawingBox As Boolean
  90. Private m_StartX As Single
  91. Private m_StartY As Single
  92. Private m_CurX As Single
  93. Private m_CurY As Single
  94. Private m_Xmin As Single
  95. Private m_Xmax As Single
  96. Private m_Ymin As Single
  97. Private m_Ymax As Single
  98. Public MaxMandelbrotIterations As Integer
  99. Public MaxJuliaIterations As Integer
  100. Public numcolors As Integer
  101. Private m_Colors() As Long
  102. Private Const MIN_X = -2.2
  103. Private Const MAX_X = 1
  104. Private Const MIN_Y = -1.2
  105. Private Const MAX_Y = 1.2
  106. ' 0 = Mandelbrot set
  107. ' 1 = Julia set
  108. Private Enum FractalTypes
  109.     fractal_Mandelbrot = 0
  110.     fractal_Julia = 1
  111. End Enum
  112. Private m_SelectedFractal As FractalTypes
  113. Private m_Mandelbrot_Xmin As Single
  114. Private m_Mandelbrot_Xmax As Single
  115. Private m_Mandelbrot_Ymin As Single
  116. Private m_Mandelbrot_Ymax As Single
  117. Private m_Julia_ReaC As Single
  118. Private m_Julia_ImaC As Single
  119. ' Draw the appropriate fractal.
  120. Private Sub DrawFractal()
  121.     If m_SelectedFractal = fractal_Mandelbrot Then
  122.         DrawMandelbrot
  123.     Else
  124.         DrawJulia
  125.     End If
  126. End Sub
  127. ' Return this color's value.
  128. Property Get color(ByVal Index As Integer) As Long
  129.     color = m_Colors(Index)
  130. End Property
  131. ' Add this color to the list.
  132. Public Sub AddColor(ByVal new_color As Long)
  133.     numcolors = numcolors + 1
  134.     ReDim Preserve m_Colors(1 To numcolors)
  135.     m_Colors(numcolors) = new_color
  136. End Sub
  137. ' Adjust the aspect ratio of the selected
  138. ' coordinates so they fit the window properly.
  139. Private Sub AdjustAspect()
  140. Dim want_aspect As Single
  141. Dim picCanvas_aspect As Single
  142. Dim hgt As Single
  143. Dim wid As Single
  144. Dim mid As Single
  145.     want_aspect = (m_Ymax - m_Ymin) / (m_Xmax - m_Xmin)
  146.     picCanvas_aspect = picCanvas.ScaleHeight / picCanvas.ScaleWidth
  147.     If want_aspect > picCanvas_aspect Then
  148.         ' The selected area is too tall and thin.
  149.         ' Make it wider.
  150.         wid = (m_Ymax - m_Ymin) / picCanvas_aspect
  151.         mid = (m_Xmin + m_Xmax) / 2
  152.         m_Xmin = mid - wid / 2
  153.         m_Xmax = mid + wid / 2
  154.     Else
  155.         ' The selected area is too short and wide.
  156.         ' Make it taller.
  157.         hgt = (m_Xmax - m_Xmin) * picCanvas_aspect
  158.         mid = (m_Ymin + m_Ymax) / 2
  159.         m_Ymin = mid - hgt / 2
  160.         m_Ymax = mid + hgt / 2
  161.     End If
  162. End Sub
  163. ' Draw the Mandelbrot set.
  164. Private Sub DrawMandelbrot()
  165. ' Work until the magnitude squared > 4.
  166. Const MAX_MAG_SQUARED = 4
  167. Dim pixels() As RGBTriplet
  168. Dim bits_per_pixel As Integer
  169. Dim wid As Long
  170. Dim hgt As Long
  171. Dim clr As Integer
  172. Dim color As Long
  173. Dim i As Integer
  174. Dim j As Integer
  175. Dim ReaC As Double
  176. Dim ImaC As Double
  177. Dim dReaC As Double
  178. Dim dImaC As Double
  179. Dim ReaZ As Double
  180. Dim ImaZ As Double
  181. Dim ReaZ2 As Double
  182. Dim ImaZ2 As Double
  183. Dim r As Integer
  184. Dim b As Integer
  185. Dim g As Integer
  186.     picCanvas.Line (0, 0)-(picCanvas.ScaleWidth, picCanvas.ScaleHeight), vbBlack, BF
  187.     DoEvents
  188.     ' Get the image's pixels.
  189.     GetBitmapPixels picCanvas, pixels, bits_per_pixel
  190.     ' Adjust the coordinate bounds to fit picCanvas.
  191.     AdjustAspect
  192.     ' dReaC is the change in the real part
  193.     ' (X value) for C. dImaC is the change in the
  194.     ' imaginary part (Y value).
  195.     wid = picCanvas.ScaleWidth
  196.     hgt = picCanvas.ScaleHeight
  197.     dReaC = (m_Xmax - m_Xmin) / (wid - 1)
  198.     dImaC = (m_Ymax - m_Ymin) / (hgt - 1)
  199.     ' Calculate the values.
  200.     ReaC = m_Xmin
  201.     For i = 0 To wid - 1
  202.         ImaC = m_Ymin
  203.         For j = 0 To hgt - 1
  204.             ReaZ = 0
  205.             ImaZ = 0
  206.             ReaZ2 = 0
  207.             ImaZ2 = 0
  208.             clr = 1
  209.             Do While clr < MaxMandelbrotIterations And _
  210.                     ReaZ2 + ImaZ2 < MAX_MAG_SQUARED
  211.                 ' Calculate Z(clr).
  212.                 ReaZ2 = ReaZ * ReaZ
  213.                 ImaZ2 = ImaZ * ImaZ
  214.                 ImaZ = 2 * ImaZ * ReaZ + ImaC
  215.                 ReaZ = ReaZ2 - ImaZ2 + ReaC
  216.                 clr = clr + 1
  217.             Loop
  218.             color = m_Colors(1 + clr Mod numcolors)
  219.             With pixels(i, j)
  220.                 .rgbRed = color And &HFF&
  221.                 .rgbGreen = (color And &HFF00&) \ &H100&
  222.                 .rgbBlue = (color And &HFF0000) \ &H10000
  223.             End With
  224.             ImaC = ImaC + dImaC
  225.         Next j
  226.         ReaC = ReaC + dReaC
  227.         ' Let the user know we're not dead.
  228.         If i Mod 10 = 0 Then
  229.             picCanvas.Line (0, 0)-(wid, i), vbWhite, BF
  230.             picCanvas.Refresh
  231.         End If
  232.     Next i
  233.     ' Update the image.
  234.     SetBitmapPixels picCanvas, bits_per_pixel, pixels
  235.     picCanvas.Refresh
  236.     picCanvas.Picture = picCanvas.Image
  237.     Caption = "Julia (" & Format$(m_Xmin) & ", " & _
  238.         Format$(m_Ymin) & ")-(" & _
  239.         Format$(m_Xmax) & ", " & _
  240.         Format$(m_Ymax) & ")"
  241. End Sub
  242. ' Draw the Mandelbrot set.
  243. Private Sub DrawJulia()
  244. ' Work until the magnitude squared > 4.
  245. Const MAX_MAG_SQUARED = 4
  246. Dim pixels() As RGBTriplet
  247. Dim bits_per_pixel As Integer
  248. Dim wid As Long
  249. Dim hgt As Long
  250. Dim clr As Long
  251. Dim color As Long
  252. Dim i As Integer
  253. Dim j As Integer
  254. Dim dReaZ0 As Double
  255. Dim dImaZ0 As Double
  256. Dim ReaZ0 As Double
  257. Dim ImaZ0 As Double
  258. Dim ReaZ As Double
  259. Dim ImaZ As Double
  260. Dim ReaZ2 As Double
  261. Dim ImaZ2 As Double
  262. Dim r As Integer
  263. Dim b As Integer
  264. Dim g As Integer
  265.     picCanvas.Line (0, 0)-(picCanvas.ScaleWidth, picCanvas.ScaleHeight), vbBlack, BF
  266.     DoEvents
  267.     ' Get the image's pixels.
  268.     GetBitmapPixels picCanvas, pixels, bits_per_pixel
  269.     ' Adjust the coordinate bounds to fit picCanvas.
  270.     AdjustAspect
  271.     ' dReaZ0 is the change in the real part
  272.     ' (X value) for Z0. dImaZ0 is the change in the
  273.     ' imaginary part (Y value).
  274.     wid = picCanvas.ScaleWidth
  275.     hgt = picCanvas.ScaleHeight
  276.     dReaZ0 = (m_Xmax - m_Xmin) / (wid - 1)
  277.     dImaZ0 = (m_Ymax - m_Ymin) / (hgt - 1)
  278.     ' Calculate the values.
  279.     ReaZ0 = m_Xmin
  280.     For i = 0 To wid - 1
  281.         ImaZ0 = m_Ymin
  282.         For j = 0 To hgt - 1
  283.             ReaZ = ReaZ0
  284.             ImaZ = ImaZ0
  285.             ReaZ2 = ReaZ * ReaZ
  286.             ImaZ2 = ImaZ * ImaZ
  287.             clr = 1
  288.             Do While clr < MaxJuliaIterations And _
  289.                     ReaZ2 + ImaZ2 < MAX_MAG_SQUARED
  290.                 ' Calculate Z(clr).
  291.                 ReaZ2 = ReaZ * ReaZ
  292.                 ImaZ2 = ImaZ * ImaZ
  293.                 ImaZ = 2 * ImaZ * ReaZ + m_Julia_ImaC
  294.                 ReaZ = ReaZ2 - ImaZ2 + m_Julia_ReaC
  295.                 clr = clr + 1
  296.             Loop
  297.             If clr >= MaxJuliaIterations Then
  298.                 ' Use a non-background color.
  299.                 color = m_Colors(((ReaZ2 + ImaZ2) * _
  300.                     (numcolors - 1)) Mod _
  301.                     (numcolors - 1) + 1)
  302.             Else
  303.                 ' Use the background color.
  304.                 color = m_Colors(1)
  305.             End If
  306.             With pixels(i, j)
  307.                 .rgbRed = color And &HFF&
  308.                 .rgbGreen = (color And &HFF00&) \ &H100&
  309.                 .rgbBlue = (color And &HFF0000) \ &H10000
  310.             End With
  311.             ImaZ0 = ImaZ0 + dImaZ0
  312.         Next j
  313.         ReaZ0 = ReaZ0 + dReaZ0
  314.         ' Let the user know we're not dead.
  315.         If i Mod 10 = 0 Then
  316.             picCanvas.Line (0, 0)-(wid, i), vbWhite, BF
  317.             picCanvas.Refresh
  318.         End If
  319.     Next i
  320.     ' Update the image.
  321.     SetBitmapPixels picCanvas, bits_per_pixel, pixels
  322.     picCanvas.Refresh
  323.     picCanvas.Picture = picCanvas.Image
  324.     Caption = "Julia (" & Format$(m_Xmin) & ", " & _
  325.         Format$(m_Ymin) & ")-(" & _
  326.         Format$(m_Xmax) & ", " & _
  327.         Format$(m_Ymax) & ")"
  328. End Sub
  329. ' Reset the number of colors to 0.
  330. Public Sub ResetColors()
  331.     numcolors = 0
  332.     Erase m_Colors
  333. End Sub
  334. ' Display the Julia set.
  335. Private Sub mnuOptJuliaSet_Click()
  336.     If m_SelectedFractal = fractal_Julia Then Exit Sub
  337.     ' Save the current Mandelbrot position.
  338.     m_Mandelbrot_Xmin = m_Xmin
  339.     m_Mandelbrot_Xmax = m_Xmax
  340.     m_Mandelbrot_Ymin = m_Ymin
  341.     m_Mandelbrot_Ymax = m_Ymax
  342.     ' Use the center as C for the Julia set.
  343.     m_Julia_ReaC = (m_Xmin + m_Xmax) / 2
  344.     m_Julia_ImaC = (m_Ymin + m_Ymax) / 2
  345.     mnuOptJuliaSet.Checked = True
  346.     mnuOptMandelbrotSet.Checked = False
  347.     m_SelectedFractal = fractal_Julia
  348.     ' Zoom out.
  349.     mnuScaleFull_Click
  350. End Sub
  351. ' Select this kind of fractal.
  352. Private Sub mnuOptMandelbrotSet_Click()
  353.     If m_SelectedFractal = fractal_Mandelbrot Then Exit Sub
  354.     ' Restore the Mandelbrot position.
  355.     m_Xmin = m_Mandelbrot_Xmin
  356.     m_Xmax = m_Mandelbrot_Xmax
  357.     m_Ymin = m_Mandelbrot_Ymin
  358.     m_Ymax = m_Mandelbrot_Ymax
  359.     mnuOptJuliaSet.Checked = False
  360.     mnuOptMandelbrotSet.Checked = True
  361.     m_SelectedFractal = fractal_Mandelbrot
  362.     ' Redraw.
  363.     Screen.MousePointer = vbHourglass
  364.     DrawFractal
  365.     Screen.MousePointer = vbDefault
  366. End Sub
  367. ' Start a rubberband box to select a zoom area.
  368. Private Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  369.     m_DrawingBox = True
  370.     m_StartX = X
  371.     m_StartY = Y
  372.     m_CurX = X
  373.     m_CurY = Y
  374.     picCanvas.DrawMode = vbInvert
  375.     picCanvas.Line (m_StartX, m_StartY)-(m_CurX, m_CurY), , B
  376. End Sub
  377. ' Continue the zoom area rubberband box.
  378. Private Sub picCanvas_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  379.     If Not m_DrawingBox Then Exit Sub
  380.     picCanvas.Line (m_StartX, m_StartY)-(m_CurX, m_CurY), , B
  381.     m_CurX = X
  382.     m_CurY = Y
  383.     picCanvas.Line (m_StartX, m_StartY)-(m_CurX, m_CurY), , B
  384. End Sub
  385. ' Zoom in on the selected area.
  386. Private Sub picCanvas_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  387. Dim x1 As Single
  388. Dim x2 As Single
  389. Dim y1 As Single
  390. Dim y2 As Single
  391. Dim factor As Single
  392.     If Not m_DrawingBox Then Exit Sub
  393.     m_DrawingBox = False
  394.     picCanvas.Line (m_StartX, m_StartY)-(m_CurX, m_CurY), , B
  395.     picCanvas.DrawMode = vbCopyPen
  396.     m_CurX = X
  397.     m_CurY = Y
  398.     ' Put the coordinates in proper order.
  399.     If m_CurX < m_StartX Then
  400.         x1 = m_CurX
  401.         x2 = m_StartX
  402.     Else
  403.         x1 = m_StartX
  404.         x2 = m_CurX
  405.     End If
  406.     If x1 = x2 Then x2 = x1 + 1
  407.     If m_CurY < m_StartY Then
  408.         y1 = m_CurY
  409.         y2 = m_StartY
  410.     Else
  411.         y1 = m_StartY
  412.         y2 = m_CurY
  413.     End If
  414.     If y1 = y2 Then y2 = y1 + 1
  415.     ' Convert screen coords into drawing coords.
  416.     factor = (m_Xmax - m_Xmin) / picCanvas.ScaleWidth
  417.     m_Xmax = m_Xmin + x2 * factor
  418.     m_Xmin = m_Xmin + x1 * factor
  419.     factor = (m_Ymax - m_Ymin) / picCanvas.ScaleHeight
  420.     m_Ymax = m_Ymin + y2 * factor
  421.     m_Ymin = m_Ymin + y1 * factor
  422.     Screen.MousePointer = vbHourglass
  423.     DrawFractal
  424.     Screen.MousePointer = vbDefault
  425. End Sub
  426. ' Force Visual Basic to resize the bitmap.
  427. Private Sub picCanvas_Resize()
  428.     picCanvas.Cls
  429. End Sub
  430. ' Save the picture.
  431. Private Sub mnuFileSaveAs_Click()
  432. Dim file_name As String
  433.     ' Allow the user to pick a file.
  434.     On Error Resume Next
  435.     dlgFile.DialogTitle = "Save As File"
  436.     dlgFile.Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly
  437.     dlgFile.ShowSave
  438.     If Err.Number = cdlCancel Then
  439.         Exit Sub
  440.     ElseIf Err.Number <> 0 Then
  441.         Beep
  442.         MsgBox "Error selecting file.", , vbExclamation
  443.         Exit Sub
  444.     End If
  445.     On Error GoTo 0
  446.     file_name = Trim$(dlgFile.FileName)
  447.     dlgFile.InitDir = Left$(file_name, Len(file_name) _
  448.         - Len(dlgFile.FileTitle) - 1)
  449.     ' Save the picture.
  450.     SavePicture picCanvas.Image, file_name
  451. End Sub
  452. ' Draw the initial Mandelbrot set.
  453. Private Sub Form_Load()
  454. Dim i As Integer
  455.     Me.Show
  456.     DoEvents
  457.     MaxMandelbrotIterations = 64
  458.     MaxJuliaIterations = 16
  459.     ' Create some default colors.
  460.     ResetColors
  461.     AddColor frmConfig.picColor(40).BackColor
  462.     For i = 17 To 23
  463.         AddColor frmConfig.picColor(i).BackColor
  464.     Next i
  465.     Unload frmConfig
  466.     dlgFile.Filter = "Bitmap Files (*.bmp)|*.bmp|" & _
  467.         "All Files (*.*)|*.*"
  468.     dlgFile.InitDir = App.Path
  469.     dlgFile.CancelError = True
  470.     ' Display the first Mandelbrot set.
  471.     mnuScaleFull_Click
  472. End Sub
  473. Private Sub Form_Resize()
  474.     picCanvas.Move 0, 0, ScaleWidth, ScaleHeight
  475. End Sub
  476. ' Let the user set program options.
  477. Private Sub mnuOptOptions_Click()
  478.     frmConfig.Initialize Me
  479.     frmConfig.Show vbModal
  480. End Sub
  481. ' Zoom out to full scale.
  482. Private Sub mnuScaleFull_Click()
  483.     m_Xmin = MIN_X
  484.     m_Xmax = MAX_X
  485.     m_Ymin = MIN_Y
  486.     m_Ymax = MAX_Y
  487.     Screen.MousePointer = vbHourglass
  488.     DrawFractal
  489.     Screen.MousePointer = vbDefault
  490. End Sub
  491. ' Make a series of images.
  492. Private Sub MakeMovie(file_name As String)
  493. Dim num_frames As Integer
  494. Dim frame As Integer
  495. Dim fraction As Single  ' Amount to reduce image.
  496. Dim xmid As Single      ' Center of image.
  497. Dim ymid As Single
  498. Dim wid1 As Single      ' Starting dimensions.
  499. Dim hgt1 As Single
  500. Dim wid2 As Single      ' Finishing dimensions.
  501. Dim hgt2 As Single
  502. Dim wid As Single       ' Current dimensions.
  503. Dim hgt As Single
  504. Dim start_time As Single
  505. Dim stop_time As Single
  506. Dim max_time As Single
  507. Dim min_time As Single
  508. Dim txt As String
  509. Dim value As Integer
  510.     ' See how may frames the user wants.
  511.     txt = InputBox("Number of frames:", _
  512.         "Frames", "20")
  513.     If txt = "" Then Exit Sub
  514.     If IsNumeric(txt) Then num_frames = CInt(txt)
  515.     If num_frames < 1 Then num_frames = 20
  516.     Screen.MousePointer = vbHourglass
  517.     max_time = 0
  518.     min_time = 100000
  519.     ' Set the center of focus and dimensions.
  520.     xmid = (m_Xmin + m_Xmax) / 2
  521.     ymid = (m_Ymin + m_Ymax) / 2
  522.     wid1 = MAX_X - MIN_X
  523.     wid2 = m_Xmax - m_Xmin
  524.     ' Compute start and finish heights.
  525.     hgt1 = wid1 * picCanvas.ScaleHeight / picCanvas.ScaleWidth
  526.     hgt2 = wid2 * picCanvas.ScaleHeight / picCanvas.ScaleWidth
  527.     ' Compute the amount to reduce the image for
  528.     ' each frame.
  529.     fraction = Exp(Log(wid2 / wid1) / (num_frames - 1))
  530.     ' Start cranking out frames.
  531.     wid = wid1
  532.     hgt = hgt1
  533.     For frame = 0 To num_frames - 1
  534.         Caption = "Julia " & Str$(frame) & _
  535.             "/" & Format$(num_frames - 1)
  536.         m_Xmin = xmid - wid / 2
  537.         m_Xmax = xmid + wid / 2
  538.         m_Ymin = ymid - hgt / 2
  539.         m_Ymax = ymid + hgt / 2
  540.         start_time = Timer
  541.         DrawFractal
  542.         stop_time = Timer
  543.         If min_time > stop_time - start_time Then min_time = stop_time - start_time
  544.         If max_time < stop_time - start_time Then max_time = stop_time - start_time
  545.         SavePicture picCanvas.Image, _
  546.             file_name & Format$(frame) & ".bmp"
  547.         Beep
  548.         DoEvents
  549.         wid = wid * fraction
  550.         hgt = hgt * fraction
  551.     Next frame
  552.     Screen.MousePointer = vbDefault
  553.     MsgBox _
  554.         "Longest:  " & Format$(max_time, "0.00") & _
  555.             " seconds." & vbCrLf & _
  556.         "Shortest: " & Format$(min_time, "0.00") & _
  557.             " seconds." & vbCrLf
  558. End Sub
  559. ' Make a series of images.
  560. Private Sub mnuMovieCreate_Click()
  561. Dim old_file_name As String
  562. Dim file_name As String
  563. Dim pos As Integer
  564.     ' Allow the user to pick a file.
  565.     On Error Resume Next
  566.     old_file_name = dlgFile.FileName
  567.     dlgFile.DialogTitle = "Select base file name (no number)"
  568.     dlgFile.Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly
  569.     pos = InStr(old_file_name, ".")
  570.     If pos > 0 Then old_file_name = Left$(old_file_name, pos - 1)
  571.     dlgFile.FileName = old_file_name
  572.     dlgFile.ShowSave
  573.     If Err.Number = cdlCancel Then
  574.         dlgFile.FileName = old_file_name
  575.         Exit Sub
  576.     ElseIf Err.Number <> 0 Then
  577.         dlgFile.FileName = old_file_name
  578.         MsgBox "Error selecting file.", , vbExclamation
  579.         Exit Sub
  580.     End If
  581.     On Error GoTo 0
  582.     file_name = Trim$(dlgFile.FileName)
  583.     dlgFile.FileName = old_file_name
  584.     dlgFile.InitDir = Left$(file_name, Len(file_name) _
  585.         - Len(dlgFile.FileTitle) - 1)
  586.     ' Trim off the extension if any.
  587.     pos = InStr(file_name, ".")
  588.     If pos > 0 Then file_name = Left$(file_name, pos - 1)
  589.     ' Add a trailing underscore if needed.
  590.     If Right$(file_name, 1) <> "_" Then _
  591.         file_name = file_name & "_"
  592.     ' Make the movie.
  593.     MakeMovie file_name
  594. End Sub
  595. ' Increase the area shown by a factor of Index.
  596. Private Sub mnuScale_Click(Index As Integer)
  597. Dim size As Single
  598. Dim mid As Single
  599.     size = Index * (m_Xmax - m_Xmin)
  600.     If size > 3.2 Then
  601.         mnuScaleFull_Click
  602.         Exit Sub
  603.     End If
  604.     mid = (m_Xmin + m_Xmax) / 2
  605.     m_Xmin = mid - size / 2
  606.     m_Xmax = mid + size / 2
  607.     size = Index * (m_Ymax - m_Ymin)
  608.     If size > 2.4 Then
  609.         mnuScaleFull_Click
  610.         Exit Sub
  611.     End If
  612.     mid = (m_Ymin + m_Ymax) / 2
  613.     m_Ymin = mid - size / 2
  614.     m_Ymax = mid + size / 2
  615.     Screen.MousePointer = vbHourglass
  616.     DrawFractal
  617.     Screen.MousePointer = vbDefault
  618. End Sub
  619.